1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 ///////////////////////////////////////////////////////////////////////////////
18 // Class to read the file coming from DCS containing the information //
19 // from LHC. Everything is stored in a TMap, where: //
20 // Key --> DP name, as passed by LHC //
21 // value --> TObjArray of AliDCSArray objects //
23 ///////////////////////////////////////////////////////////////////////////////
25 #include <Riostream.h>
28 #include <TObjArray.h>
29 #include <TObjString.h>
35 #include "AliDCSArray.h"
36 #include "AliLHCReader.h"
39 //--------------------------------------------------------------------------
40 AliLHCReader::AliLHCReader():
48 //--------------------------------------------------------------------------
49 AliLHCReader::~AliLHCReader()
56 //--------------------------------------------------------------------------
57 TMap* AliLHCReader::ReadLHCDP(TString filename)
60 // reading the file with the inputs
63 if( gSystem->AccessPathName( filename.Data() ) ) {
64 AliError(Form( "file (%s) not found", filename.Data() ) );
68 ifstream *file = new ifstream ( filename.Data() );
70 AliError(Form("Error opening file (%s) !",filename.Data()));
75 TMap* mapLHC = new TMap();
78 while(strLine.ReadLine(*file)){
79 // tokenize the line with tabs
80 TObjArray* tokens = strLine.Tokenize(" \t");
81 Int_t ntokens = tokens->GetEntriesFast();
83 // requiring at least the DP name, the format, and the number of entries
87 TObjString* lhcDPname = (TObjString*)tokens->At(0);
88 TString lhcDPtype = ((TObjString*)tokens->At(1))->String();
89 AliDebug(2,Form("lhcDPtype = %s",lhcDPtype.Data()));
90 TObjArray* typeTokens = lhcDPtype.Tokenize(":");
91 if (typeTokens->GetEntriesFast() < 2 ){
92 // requiring the the type and the number of elements for each measurement
93 AliError(Form("The format does not match the expected one, skipping the current line for DP = %s", lhcDPtype.Data()));
97 TString type = ((TObjString*)typeTokens->At(0))->String();
98 AliDebug(2,Form("type = %s",type.Data()));
99 Int_t nelements = (((TObjString*)typeTokens->At(1))->String()).Atoi();
100 AliDebug(2,Form("nelements = %i",nelements));
101 Int_t nentries = (((TObjString*)tokens->At(2))->String()).Atoi();
102 AliDebug(2,Form("nentries = %i",nentries));
103 Int_t nValuesPerEntry = nelements+1;
104 Int_t nfixed = 3; // n. of fixed entries
105 TObjArray* array = new TObjArray();
107 for (Int_t ientry=0; ientry< nentries; ientry ++){
108 Int_t indextime = nfixed+nValuesPerEntry*ientry+nelements;
109 TString strTimestamp = ((TObjString*)tokens->At(indextime))->String();
110 TObjArray* timeTokens = strTimestamp.Tokenize(".");
111 if (timeTokens->GetEntriesFast() < 2 ){
112 // requiring both the seconds and the nseconds for the timestamp
113 AliError(Form("The timestamp format does not match the expected one, skipping entry %d for DP = %s", ientry, lhcDPtype.Data()));
116 time_t seconds = time_t((((TObjString*)timeTokens->At(0))->String()).Atoi());
117 Int_t nseconds = Int_t((((TObjString*)timeTokens->At(1))->String()).Atoi());
118 TTimeStamp* timestamp = new TTimeStamp(seconds, nseconds);
119 AliDebug(2,Form("Timestamp in unix time = %d (s) = %d (ns)",timestamp->GetSec(),timestamp->GetNanoSec()));
120 if (fStartTime!=0 && fEndTime!=0 && (fStartTime > (UInt_t)timestamp->GetSec() || fEndTime < (UInt_t)timestamp->GetSec())){
121 // error in case the measurement is not within the data taking time interval
122 AliError(Form("Timestamp for entry %d of DP %s not in [%d,%d]", ientry, lhcDPtype.Data(),fStartTime,fEndTime));
126 Int_t* value = new Int_t[nelements];
127 for (Int_t ielement=0; ielement<nelements; ielement++){
128 value[ielement] = (((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atoi();
129 AliDebug(2,Form("Value at index %d = %d",nfixed+ielement+ientry*nValuesPerEntry,value[ielement]));
131 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
134 else if (type == "f"){
135 Float_t* value = new Float_t[nelements];
136 for (Int_t ielement=0; ielement<nelements; ielement++){
137 value[ielement] = (((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String()).Atof();
138 AliDebug(2,Form("Value at index %d = %f",nfixed+ielement+ientry*nValuesPerEntry,value[ielement]));
140 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
143 else if (type == "s"){
144 TString* value = new TString[nelements];
145 for (Int_t ielement=0; ielement<nelements; ielement++){
146 value[ielement] = ((TObjString*)tokens->At(nfixed+ielement+ientry*nValuesPerEntry))->String();
147 AliDebug(2,Form("Value at index %d = %s",nfixed+ielement+ientry*nValuesPerEntry,value[ielement].Data()));
149 AliDCSArray* dcs = new AliDCSArray(nelements,value,timestamp);
153 AliError("Non-expected type");
157 mapLHC->Add(lhcDPname,array);