Adding classes to read LHC DP file coming from DCS.
authorzampolli <zampolli@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 2 Jul 2009 14:45:09 +0000 (14:45 +0000)
committerzampolli <zampolli@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 2 Jul 2009 14:45:09 +0000 (14:45 +0000)
New classes put in libSTEER.

STEER/AliDCSArray.cxx [new file with mode: 0644]
STEER/AliDCSArray.h [new file with mode: 0644]
STEER/AliLHCReader.cxx [new file with mode: 0644]
STEER/AliLHCReader.h [new file with mode: 0644]
STEER/STEERLinkDef.h
STEER/libSTEER.pkg

diff --git a/STEER/AliDCSArray.cxx b/STEER/AliDCSArray.cxx
new file mode 100644 (file)
index 0000000..3af3222
--- /dev/null
@@ -0,0 +1,314 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+////////////////////////////////////////////////////////////////////////////////
+//                                                                            //
+// This class represents the value(s) of a the LHC DPs at a given timestamp   //
+// The variuos measurement that occurred at the same timestamp are associated //
+// to the same timestamp.                                                     //  
+//                                                                            //
+////////////////////////////////////////////////////////////////////////////////
+
+
+#include "AliDCSArray.h"
+
+#include "TTimeStamp.h"
+#include <TString.h>
+
+ClassImp(AliDCSArray)
+       
+AliDCSArray::AliDCSArray() :
+               TObject(),
+               fType(kInvalid),
+               fnentries(0),
+               fBool(0x0),
+               fChar(0x0),
+               fInt(0x0),
+               fUInt(0x0),
+               fFloat(0x0),
+               fString(0x0),
+               fTimeStamp(0)
+{
+       //
+       // default constructor
+       //
+}
+
+//--------------------------------------------------------------------------
+AliDCSArray::AliDCSArray(Int_t nentries, Bool_t* value, TTimeStamp* timeStamp) : 
+       TObject(),
+       fType(kBool),
+       fnentries(nentries),
+       fBool(new Bool_t[fnentries]),
+       fChar(0x0),
+       fInt(0x0),
+       fUInt(0x0),
+       fFloat(0x0),
+       fString(0x0),
+       fTimeStamp(timeStamp)
+{
+       //
+       // constructor for Bool
+       //
+       
+       for (Int_t i = 0; i<fnentries; i++){
+               fBool[i] = value[i];
+       }
+}
+
+//--------------------------------------------------------------------------
+AliDCSArray::AliDCSArray(Int_t nentries, Char_t* value, TTimeStamp* timeStamp) :
+       TObject(),
+       fType(kChar),
+       fnentries(nentries),
+       fBool(0x0),
+       fChar(new Char_t[fnentries]),
+       fInt(0x0),
+       fUInt(0x0),
+       fFloat(0x0),
+       fString(0x0),
+       fTimeStamp(timeStamp)
+{
+       //
+       // constructor for Char
+       //
+       for (Int_t i = 0; i<fnentries; i++){
+               fChar[i] = value[i];
+       }
+}
+
+//-------------------------------------------------------------------------
+AliDCSArray::AliDCSArray(Int_t nentries, Int_t* value, TTimeStamp* timeStamp) :
+       TObject(),
+       fType(kInt),
+       fnentries(nentries),
+       fBool(0x0),
+       fChar(0x0),
+       fInt(new Int_t[fnentries]),
+       fUInt(0x0),
+       fFloat(0x0),
+       fString(0x0),
+       fTimeStamp(timeStamp)
+{
+       //
+       // constructor for Int
+       //
+       for (Int_t i = 0; i<fnentries; i++){
+               fInt[i] = value[i];
+       }
+}
+
+//-------------------------------------------------------------------------
+AliDCSArray::AliDCSArray(Int_t nentries, UInt_t* value, TTimeStamp* timeStamp) :
+       TObject(),
+       fType(kUInt),
+       fnentries(nentries),
+       fBool(0x0),
+       fChar(0x0),
+       fInt(0x0),
+       fUInt(new UInt_t[fnentries]),
+       fFloat(0x0),
+       fString(0x0),
+       fTimeStamp(timeStamp)
+{
+       //
+       // constructor for UInt
+       //
+
+       for (Int_t i = 0; i<fnentries; i++){
+               fUInt[i] = value[i];
+       }
+}
+
+//-------------------------------------------------------------------------
+AliDCSArray::AliDCSArray(Int_t nentries, Float_t* value, TTimeStamp* timeStamp) :
+       TObject(),
+       fType(kFloat),
+       fnentries(nentries),
+       fBool(0x0),
+       fChar(0x0),
+       fInt(0x0),
+       fUInt(0x0),
+       fFloat(new Float_t[fnentries]),
+       fString(0x0),
+       fTimeStamp(timeStamp)
+{
+       //
+       // constructor for Float
+       //
+
+       for (Int_t i = 0; i<fnentries; i++){
+               fFloat[i] = value[i];
+       }
+}
+
+//------------------------------------------------------------------------
+AliDCSArray::AliDCSArray(Int_t nentries, TString* value, TTimeStamp* timeStamp) :
+       TObject(),
+       fType(kString),
+       fnentries(nentries),
+       fBool(0x0),
+       fChar(0x0),
+       fInt(0x0),
+       fUInt(0x0),
+       fFloat(0x0),
+       fString(new TString[fnentries]),
+       fTimeStamp(timeStamp)
+{
+       //
+       // constructor for String
+       //
+
+       for (Int_t i = 0; i<fnentries; i++){
+               fString[i] = value[i];
+       }
+}
+
+//-----------------------------------------------------------------------
+AliDCSArray::AliDCSArray(const AliDCSArray& c) :
+       TObject(c),
+       fType(c.fType),
+       fnentries(c.fnentries),
+       fBool(0x0),
+       fChar(0x0),
+       fInt(0x0),
+       fUInt(0x0),
+       fFloat(0x0),
+       fString(0x0),
+       fTimeStamp(c.fTimeStamp)
+{
+       //
+       // copy constructor
+       //
+       
+       if (fType == kBool && c.fBool){
+               fBool = new Bool_t[fnentries];
+               memcpy(fBool,c.fBool,fnentries*sizeof(Bool_t));
+       } 
+       if (fType == kChar && c.fChar){
+               fChar = new Char_t[fnentries];
+               memcpy(fChar,c.fChar,fnentries*sizeof(Char_t));
+       } 
+       if (fType == kUInt && c.fUInt){
+               fUInt = new UInt_t[fnentries];
+               memcpy(fUInt,c.fUInt,fnentries*sizeof(UInt_t));
+       } 
+       if (fType == kInt && c.fInt){
+               fInt = new Int_t[fnentries];
+               memcpy(fInt,c.fInt,fnentries*sizeof(Int_t));
+       } 
+       if (fType == kFloat && c.fFloat){
+               fFloat = new Float_t[fnentries];
+               memcpy(fFloat,c.fFloat,fnentries*sizeof(Float_t));
+       } 
+       if (fType == kString && c.fString){
+               fString = new TString[fnentries];
+               memcpy(fString,c.fString,fnentries*sizeof(TString));
+       } 
+
+}
+
+//-----------------------------------------------------------------------
+AliDCSArray::~AliDCSArray()
+{
+       //
+       // destructor
+       //
+
+       if (fBool){
+               fBool = 0x0;
+               delete fBool;
+       }
+       if (fChar){
+               fChar = 0x0;
+               delete fChar;
+       }
+       if (fUInt){
+               fUInt = 0x0;
+               delete fUInt;
+       }
+       if (fInt){
+               fInt = 0x0;
+               delete fInt;
+       }
+       if (fFloat){
+               fFloat = 0x0;
+               delete fFloat;
+       }
+       if (fString){
+               fString = 0x0;
+               delete fString;
+       }
+       if (fTimeStamp){
+               fTimeStamp = 0x0;
+               delete fTimeStamp;
+       }
+}
+
+//-----------------------------------------------------------------------
+AliDCSArray &AliDCSArray::operator=(const AliDCSArray &c)
+{
+       //
+       // operator = 
+       //
+       
+       if(&c == this) return *this;
+       if (fType == kBool && c.fBool){
+               fBool = new Bool_t[fnentries];
+               memcpy(fBool,c.fBool,fnentries*sizeof(Bool_t));
+       } 
+       if (fType == kChar && c.fChar){
+               fChar = new Char_t[fnentries];
+               memcpy(fChar,c.fChar,fnentries*sizeof(Char_t));
+       } 
+       if (fType == kUInt && c.fUInt){
+               fUInt = new UInt_t[fnentries];
+               memcpy(fUInt,c.fUInt,fnentries*sizeof(UInt_t));
+       } 
+       if (fType == kInt && c.fInt){
+               fInt = new Int_t[fnentries];
+               memcpy(fInt,c.fInt,fnentries*sizeof(Int_t));
+       } 
+       if (fType == kFloat && c.fFloat){
+               fFloat = new Float_t[fnentries];
+               memcpy(fFloat,c.fFloat,fnentries*sizeof(Float_t));
+       } 
+       if (fType == kString && c.fString){
+               fString = new TString[fnentries];
+               memcpy(fString,c.fString,fnentries*sizeof(TString));
+       } 
+       
+       return *this;
+}
+
+//-----------------------------------------------------------------------
+void AliDCSArray::Init()
+{
+       //
+       // init helper, that initializes everything to 0
+       //
+       
+       fType = kInvalid;
+       
+       fnentries = 0;
+       fBool = 0x0;
+       fChar = 0x0;
+       fInt = 0x0;
+       fUInt = 0x0;
+       fFloat = 0x0;
+       fString = 0x0;
+       
+       fTimeStamp = 0x0;
+}
diff --git a/STEER/AliDCSArray.h b/STEER/AliDCSArray.h
new file mode 100644 (file)
index 0000000..51c7963
--- /dev/null
@@ -0,0 +1,77 @@
+#ifndef ALI_DCS_ARRAY_H
+#define ALI_DCS_ARRAY_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+////////////////////////////////////////////////////////////////////////////////
+//                                                                            //
+// This class represents the value(s) of a the LHC DPs at a given timestamp   //
+//                                                                            //
+////////////////////////////////////////////////////////////////////////////////
+
+#include <TObject.h>
+#include <TString.h>
+#include <TTimeStamp.h>
+
+class AliDCSArray : public TObject {
+ public:
+       enum Type {
+               kInvalid = 0,
+               kBool = 1,
+               kChar = 2,
+               kInt = 3,
+               kUInt = 4,
+               kFloat = 5,
+               kString = 6
+       };
+       
+       AliDCSArray();
+       AliDCSArray(const AliDCSArray& c);
+       
+       virtual ~AliDCSArray();
+       
+       AliDCSArray& operator=(const AliDCSArray& c);
+       
+       AliDCSArray(Int_t nentries, Bool_t* value, TTimeStamp* timeStamp);
+       AliDCSArray(Int_t nentries, Char_t* value, TTimeStamp* timeStamp);
+       AliDCSArray(Int_t nentries, Int_t* value, TTimeStamp* timeStamp);
+       AliDCSArray(Int_t nentries, UInt_t* value, TTimeStamp* timeStamp);
+       AliDCSArray(Int_t nentries, Float_t* value, TTimeStamp* timeStamp);
+       AliDCSArray(Int_t nentries, TString* value, TTimeStamp* timeStamp);
+       
+       Int_t GetNEntries() const { return fnentries;}
+       Bool_t* GetBool() const { return fBool; }
+       Char_t* GetChar() const { return fChar; }
+       Int_t* GetInt() const { return fInt; }
+       UInt_t* GetUInt() const { return fUInt; }
+       Float_t* GetFloat() const { return fFloat; }
+       TString* GetString() const { return fString; }
+       
+       Type GetType() const { return fType; }
+       
+       TTimeStamp* GetTimeStamp() const { return fTimeStamp; }
+       void SetTimeStamp(TTimeStamp* timeStamp) { fTimeStamp = timeStamp; }
+       
+ protected:
+       
+       void Init();
+       
+       Type fType;            // type of the value stored
+       
+       Int_t fnentries;       // n. of entries at the same timestamp
+       Bool_t* fBool;         //[fnentries] bool value
+       Char_t* fChar;         //[fnentries] char value
+       Int_t* fInt;           //[fnentries] int value
+       UInt_t* fUInt;         //[fnentries] uint value
+       Float_t* fFloat;       //[fnentries] float value
+       TString* fString;      //[fnentries] string value
+       
+       TTimeStamp* fTimeStamp;    // timestamp of this value
+       
+       ClassDef(AliDCSArray, 1);
+};
+
+#endif
diff --git a/STEER/AliLHCReader.cxx b/STEER/AliLHCReader.cxx
new file mode 100644 (file)
index 0000000..0ece0f2
--- /dev/null
@@ -0,0 +1,168 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+///////////////////////////////////////////////////////////////////////////////
+//                                                                           //
+//  Class to read the file coming from DCS containing the information        //
+//  from LHC. Everything is stored in a TMap, where:                         //
+//  Key   --> DP name, as passed by LHC                                      // 
+//  value --> TObjArray of AliDCSArray objects                               //
+//                                                                           //
+///////////////////////////////////////////////////////////////////////////////
+
+#include <Riostream.h>
+#include <time.h>
+
+#include <TObjArray.h>
+#include <TObjString.h>
+#include <TObject.h>
+#include <TString.h>
+#include <TMap.h>
+#include <TSystem.h>
+
+#include "AliDCSArray.h"
+#include "AliLHCReader.h"
+#include "AliLog.h"
+
+//--------------------------------------------------------------------------
+AliLHCReader::AliLHCReader():
+       TObject(),
+       fStartTime(0),
+       fEndTime(0)
+{
+       // default ctor 
+}
+
+//--------------------------------------------------------------------------
+AliLHCReader::~AliLHCReader()
+{
+       //
+       // dtor 
+       //
+}
+
+//--------------------------------------------------------------------------
+TMap* AliLHCReader::ReadLHCDP(TString filename)
+{
+       //
+       // reading the file with the inputs
+       //
+
+               if( gSystem->AccessPathName( filename.Data() ) ) {
+               AliError(Form( "file (%s) not found", filename.Data() ) );
+               return NULL;
+       }
+
+       ifstream *file = new ifstream ( filename.Data() );
+       if (!*file) {
+               AliError(Form("Error opening file (%s) !",filename.Data()));
+               file->close();
+               delete file;
+               return NULL;
+       }
+       TMap* mapLHC = new TMap();
+       mapLHC->SetOwner(1);
+       TString strLine;
+       while(strLine.ReadLine(*file)){
+               // tokenize the line with tabs
+               TObjArray* tokens = strLine.Tokenize(" \t");
+               Int_t ntokens = tokens->GetEntriesFast();
+               if (ntokens < 3){  
+                       // requiring at least the DP name, the format, and the number of entries
+                       delete tokens;
+                       continue;
+               }
+               TObjString* lhcDPname = (TObjString*)tokens->At(0);
+               TString lhcDPtype = ((TObjString*)tokens->At(1))->String();
+               AliDebug(2,Form("lhcDPtype = %s",lhcDPtype.Data()));
+               TObjArray* typeTokens = lhcDPtype.Tokenize(":");
+               if (typeTokens->GetEntriesFast() < 2 ){  
+                       // requiring the the type and the number of elements for each measurement
+                       AliError(Form("The format does not match the expected one, skipping the current line for DP = %s", lhcDPtype.Data()));
+                       delete typeTokens;
+                       continue;
+               }
+               TString type = ((TObjString*)typeTokens->At(0))->String();
+               AliDebug(2,Form("type = %s",type.Data()));
+               Int_t nelements = (((TObjString*)typeTokens->At(1))->String()).Atoi();
+               AliDebug(2,Form("nelements = %i",nelements));
+               Int_t nentries = (((TObjString*)tokens->At(2))->String()).Atoi();
+               AliDebug(2,Form("nentries = %i",nentries));
+               Int_t nValuesPerEntry = nelements+1;
+               Int_t nfixed = 3; // n. of fixed entries
+               TObjArray* array = new TObjArray();
+               array->SetOwner(1);
+               for (Int_t ientry=0; ientry< nentries; ientry ++){
+                       Int_t indextime = nfixed+nValuesPerEntry*ientry+nelements;
+                       TString strTimestamp = ((TObjString*)tokens->At(indextime))->String();
+                       TObjArray* timeTokens = strTimestamp.Tokenize(".");
+                       if (timeTokens->GetEntriesFast() < 2 ){  
+                               // requiring both the seconds and the nseconds for the timestamp
+                               AliError(Form("The timestamp format does not match the expected one, skipping entry %d for DP = %s", ientry, lhcDPtype.Data()));
+                               continue;
+                       }
+                       time_t seconds = time_t((((TObjString*)timeTokens->At(0))->String()).Atoi());
+                       Int_t nseconds = Int_t((((TObjString*)timeTokens->At(1))->String()).Atoi());
+                       TTimeStamp* timestamp = new TTimeStamp(seconds, nseconds);
+                       AliDebug(2,Form("Timestamp in unix time = %d (s) = %d (ns)",timestamp->GetSec(),timestamp->GetNanoSec()));
+                       if (fStartTime!=0 && fEndTime!=0 && (fStartTime > (UInt_t)timestamp->GetSec() || fEndTime < (UInt_t)timestamp->GetSec())){
+                               // error in case the measurement is not within the data taking time interval
+                               AliError(Form("Timestamp for entry %d of DP %s not in [%d,%d]", ientry, lhcDPtype.Data(),fStartTime,fEndTime));
+                               continue;
+                       }
+                       if (type == "i"){
+                               Int_t* value = new Int_t[nelements];
+                               for (Int_t ielement=0; ielement<nelements; ielement++){
+                                       value[ielement] = (((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atoi();
+                                       AliDebug(2,Form("Value at index %d = %d",nfixed+ielement+ientry*nValuesPerEntry,value[ielement]));
+                               }
+                               AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
+                               array->Add(dcs);
+                       }
+                       else if (type == "f"){
+                               Float_t* value = new Float_t[nelements];
+                               for (Int_t ielement=0; ielement<nelements; ielement++){
+                                       value[ielement] = (((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atof();
+                                       AliDebug(2,Form("Value at index %d = %f",nfixed+ielement+ientry*nValuesPerEntry,value[ielement]));
+                               } 
+                               AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
+                               array->Add(dcs);
+                       } 
+                       else if (type == "s"){
+                               TString* value = new TString[nelements];
+                               for (Int_t ielement=0; ielement<nelements; ielement++){
+                                       value[ielement] = ((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String();
+                                       AliDebug(2,Form("Value at index %d = %s",nfixed+ielement+ientry*nValuesPerEntry,value[ielement].Data()));
+                               }
+                               AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
+                               array->Add(dcs);
+                       }
+                       else{
+                               AliError("Non-expected type");
+                               return NULL;
+                       } 
+               }
+               mapLHC->Add(lhcDPname,array);                   
+       }
+       return mapLHC;
+}
+
+                               
+
+
+
+
+
+
diff --git a/STEER/AliLHCReader.h b/STEER/AliLHCReader.h
new file mode 100644 (file)
index 0000000..8d76419
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef ALILHCREADER_H
+#define ALILHCREADER_H
+
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+///////////////////////////////////////////////////////////////////////////////
+//                                                                           //
+//  Class to read the file coming from DCS containing the information        //
+//  from LHC.                                                                //
+//                                                                           //
+///////////////////////////////////////////////////////////////////////////////
+
+class TString;
+class TMap;
+
+#include <TObject.h>
+
+class AliLHCReader : public TObject{
+ public:
+       AliLHCReader(); // default ctor
+       virtual ~AliLHCReader();
+       TMap* ReadLHCDP(TString lhcDP);
+
+       UInt_t GetStartTime() const {return fStartTime;}
+       UInt_t GetEndTime() const {return fEndTime;}
+
+       void SetStartTime(UInt_t startTime) {fStartTime=startTime;}
+       void SetEndTime(UInt_t endTime) {fEndTime = endTime;}
+
+ private:
+       AliLHCReader& operator=(const AliLHCReader *reader); // assignment operator
+       AliLHCReader(const AliLHCReader *reader); // copy ctor
+
+       UInt_t fStartTime;   // start time of data taking
+       UInt_t fEndTime;     // end time of data taking
+
+       ClassDef(AliLHCReader,0)
+               };
+#endif
index c1d1272..144a713 100644 (file)
 #pragma link C++ class AliRectMatrix+;
 
 #pragma link C++ class AliGRPManager+;
+#pragma link C++ class AliDCSArray+;
+#pragma link C++ class AliLHCReader+;
 
 #endif
index f356fcb..9004267 100644 (file)
@@ -71,7 +71,8 @@ AliRecoParam.cxx AliDetectorRecoParam.cxx \
 AliMillePedeRecord.cxx AliMillePede2.cxx AliMatrixSq.cxx \
 AliVectorSparse.cxx AliMatrixSparse.cxx \
 AliSymMatrix.cxx AliRectMatrix.cxx AliMinResSolve.cxx \
-AliGRPManager.cxx
+AliGRPManager.cxx \
+AliDCSArray.cxx AliLHCReader.cxx
 
 HDRS:= $(SRCS:.cxx=.h)