]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliLHCReader.cxx
Corrected protection.
[u/mrichter/AliRoot.git] / STEER / AliLHCReader.cxx
index 5ea1ed69ca45ffe96c395af731c67c8e94993d8b..287b61b40c9458af6ff7d3571a2e8842f06ce23a 100644 (file)
@@ -60,7 +60,7 @@ TMap* AliLHCReader::ReadLHCDP(TString filename)
        //
        // reading the file with the inputs
        //
-
+  gSystem->ExpandPathName(filename);
                if( gSystem->AccessPathName( filename.Data() ) ) {
                AliError(Form( "file (%s) not found", filename.Data() ) );
                return NULL;
@@ -74,11 +74,10 @@ TMap* AliLHCReader::ReadLHCDP(TString filename)
                return NULL;
        }
        TMap* mapLHC = new TMap();
-       //      mapLHC->SetOwner(1);
+       mapLHC->SetOwnerKeyValue();
        TString strLine;
        Int_t lhcEntries;
        Int_t nBlocks = 0;
-       //      TObjArray** array;
        Int_t nline =0;
        while(strLine.ReadLine(*file)){
                nline++;
@@ -87,12 +86,20 @@ TMap* AliLHCReader::ReadLHCDP(TString filename)
                //if (strLine.BeginsWith("=")) continue;
                //if (!strLine.CompareTo("END_OF_BLOCK")) {
                if (strLine.Contains("END_OF_BLOCK")) {
-                       AliInfo("END_OF_BLOCK");
+                       AliDebug(2,"END_OF_BLOCK");
                        nBlocks++;
                        continue;
                }
                TObjArray* tokens = strLine.Tokenize("\t");
                Int_t ntokens = tokens->GetEntriesFast();
+               //
+               if ( strLine.Contains("LHC_ENTRIES ") ) {
+                 // RS: special treatment for "LHC_ENTRIES N" record, which is space (and not tab) separated)
+                 delete tokens;
+                 tokens = strLine.Tokenize(" ");
+                 ntokens = tokens->GetEntriesFast();
+               }
+               //
                AliDebug(3,Form("Number of tokens = %d",ntokens));
                if (ntokens == 2 && !(((TObjString*)tokens->At(0))->String()).CompareTo("LHC_ENTRIES")){
                        lhcEntries = (((TObjString*)tokens->At(1))->String()).Atoi();
@@ -101,7 +108,8 @@ TMap* AliLHCReader::ReadLHCDP(TString filename)
                        continue;
                }
                if (ntokens == 1 && !(((TObjString*)tokens->At(0))->String()).CompareTo("END_OF_DATA")){
-                       AliInfo("End of file reached");
+                       AliDebug(2,"End of file reached");
+                       delete tokens;
                        break;
                }
                if (ntokens < 4){  
@@ -114,13 +122,14 @@ TMap* AliLHCReader::ReadLHCDP(TString filename)
                AliDebug(2,Form("lhcDPindex = %d",lhcDPindex));
                TObjString* lhcDPname = (TObjString*)tokens->At(1);
                TString lhcDPtype = ((TObjString*)tokens->At(2))->String();
-               AliInfo(Form("lhcDPname = %s",(lhcDPname->String()).Data()));
+               AliDebug(2,Form("lhcDPname = %s",(lhcDPname->String()).Data()));
                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;
+                       delete tokens;
                        continue;
                }
                TString type = ((TObjString*)typeTokens->At(0))->String();
@@ -135,25 +144,16 @@ TMap* AliLHCReader::ReadLHCDP(TString filename)
                if (mapLHC->GetValue(lhcDPname)==0x0){
                        array = new TObjArray();
                        array->SetOwner(1);
+                       mapLHC->Add(new TObjString(lhcDPname->String()),array);                 
                }
                else{
-                       TPair* p = mapLHC->RemoveEntry(lhcDPname);
-                       array = (TObjArray*)p->Value();
+                       array = (TObjArray*)mapLHC->GetValue(lhcDPname);
                        AliDebug(2,Form("entry found! --> %p",array));
                }
                                        
                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, (Int_t)(nseconds*1E8));
                        Double_t timestamp = strTimestamp.Atof();
                        AliDebug(2,Form("Timestamp in unix time = %f (s)",timestamp));
                        if (fStartTime!=0 && fEndTime!=0 && (fStartTime > timestamp || fEndTime < timestamp)){
@@ -169,6 +169,7 @@ TMap* AliLHCReader::ReadLHCDP(TString filename)
                                }
                                AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
                                array->Add(dcs);
+                               delete[] value;
                        }
                        else if (type == "b"){
                                Bool_t* value = new Bool_t[nelements];
@@ -178,6 +179,7 @@ TMap* AliLHCReader::ReadLHCDP(TString filename)
                                }
                                AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
                                array->Add(dcs);
+                               delete[] value;
                        }
                        else if (type == "f"){ // the floats should be considered as doubles
                                Double_t* value = new Double_t[nelements];
@@ -188,29 +190,168 @@ TMap* AliLHCReader::ReadLHCDP(TString filename)
                                } 
                                AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
                                array->Add(dcs);
+                               delete[] value;
                        } 
                        else if (type == "s"){
                                TObjArray* value = new TObjArray();
+                               value->SetOwner(1);
                                for (Int_t ielement=0; ielement<nelements; ielement++){
-                                       TObjString* strobj = ((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry));
+                                 TObjString* strobj = (new TObjString(((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()));
                                        AliDebug(2,Form("Value at index %d = %s",nfixed+ielement+ientry*nValuesPerEntry,(strobj->String()).Data()));
                                        value->Add(strobj);
                                }
                                AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
                                array->Add(dcs);
+                               delete value;
                        }
                        else{
                                AliError(Form("Non-expected type %s",type.Data()));
+                               delete typeTokens;
+                               delete tokens;  
+                               file->close();
+                               delete file;    
                                return NULL;
                        } 
                }
-               mapLHC->Add(lhcDPname,array);                   
+               delete typeTokens;
+               delete tokens;
        }
-       //mapLHC->Print();
+       file->close();
+       delete file;
        return mapLHC;
 }
 
-                               
+//--------------------------------------------------------------------------
+TObjArray* AliLHCReader::ReadSingleLHCDP(TString filename, TString alias)
+{
+       //
+       // reading the file with the inputs for the selected alias
+       // returning the TObjArray containing the information only for the current alias
+       //
+  gSystem->ExpandPathName(filename);
+               if( gSystem->AccessPathName( filename.Data() ) ) {
+               AliError(Form( "file (%s) not found", filename.Data() ) );
+               return NULL;
+       }
+
+       TString selection = gSystem->GetFromPipe(Form("grep -P '^\\d+\\s+%s+\\s' %s",alias.Data(), filename.Data()));
+
+       if (selection.Length() == 0) {
+               AliError(Form("Alias %s not fouond in LHC Data file, returning a null pointer",alias.Data()));
+               return NULL;
+       }
+
+       Int_t nline =0;
+
+       TObjArray* tokenslines = selection.Tokenize("\n");
+       Int_t ntokenslines = tokenslines->GetEntriesFast();
+       AliDebug(3,Form("Number of tokenslines = %d",ntokenslines));
+
+       TObjArray* array = new TObjArray(); // array to be returned
+       array->SetOwner(1);
+
+       for (Int_t iline=0; iline<ntokenslines; iline++){
+               TString strLine = ((TObjString*)tokenslines->At(iline))->String();
+               AliDebug(4,Form("***************** line = %s\n",strLine.Data()));
+               TObjArray* tokens = strLine.Tokenize("\t");
+               Int_t ntokens = tokens->GetEntriesFast();
+               AliDebug(3,Form("Number of tokens = %d",ntokens));
+               if (ntokens < 4){  
+                       AliInfo(Form("Wrong number of tokens --> # tokens = %d at line %d",ntokens,nline));
+                       // requiring at least the index of the DP, the DP name, the format, and the number of entries
+                       delete tokens;
+                       continue;
+               }
+               Int_t lhcDPindex = (((TObjString*)tokens->At(0))->String()).Atoi();
+               AliDebug(2,Form("lhcDPindex = %d",lhcDPindex));
+               TObjString* lhcDPname = (TObjString*)tokens->At(1);
+               TString lhcDPtype = ((TObjString*)tokens->At(2))->String();
+               AliDebug(2,Form("lhcDPname = %s",(lhcDPname->String()).Data()));
+               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;
+                       delete tokens;
+                       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(3))->String()).Atoi();
+               AliDebug(2,Form("nentries = %i",nentries));
+               Int_t nValuesPerEntry = nelements+1;
+               Int_t nfixed = 4; // n. of fixed entries
+               for (Int_t ientry=0; ientry< nentries; ientry ++){
+                       Int_t indextime = nfixed+nValuesPerEntry*ientry+nelements;
+                       TString strTimestamp = ((TObjString*)tokens->At(indextime))->String();
+                       Double_t timestamp = strTimestamp.Atof();
+                       AliDebug(2,Form("Timestamp in unix time = %f (s)",timestamp));
+                       if (fStartTime!=0 && fEndTime!=0 && (fStartTime > timestamp || fEndTime < timestamp)){
+                               // 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);
+                               delete[] value;
+                       }
+                       else if (type == "b"){
+                               Bool_t* value = new Bool_t[nelements];
+                               for (Int_t ielement=0; ielement<nelements; ielement++){
+                                       value[ielement] = Bool_t((((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atoi());
+                                       AliDebug(2,Form("Value at index %d = %d",nfixed+ielement+ientry*nValuesPerEntry,Int_t(value[ielement])));
+                               }
+                               AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
+                               array->Add(dcs);
+                               delete[] value;
+                       }
+                       else if (type == "f"){ // the floats should be considered as doubles
+                               Double_t* value = new Double_t[nelements];
+                               for (Int_t ielement=0; ielement<nelements; ielement++){
+                                       TString tempstr = (TString)(((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String());
+                                       value[ielement] = (((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atof();
+                                       AliDebug(2,Form("Value at index %d = %f from string %s",nfixed+ielement+ientry*nValuesPerEntry,value[ielement],tempstr.Data()));
+                               } 
+                               AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
+                               array->Add(dcs);
+                               delete[] value;
+                       } 
+                       else if (type == "s"){
+                               TObjArray* value = new TObjArray();
+                               value->SetOwner(1);
+                               for (Int_t ielement=0; ielement<nelements; ielement++){
+                                 TObjString* strobj = (new TObjString(((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()));
+                                       AliDebug(2,Form("Value at index %d = %s",nfixed+ielement+ientry*nValuesPerEntry,(strobj->String()).Data()));
+                                       value->Add(strobj);
+                               }
+                               AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
+                               array->Add(dcs);
+                               delete value;
+                       }
+                       else{
+                               AliError(Form("Non-expected type %s",type.Data()));
+                               delete typeTokens;
+                               delete tokens;  
+                               delete tokenslines;
+                               return NULL;
+                       } 
+               }
+               delete typeTokens;
+               delete tokens;
+       }
+       delete tokenslines;
+       return array;
+}
+