/[PAMELA software]/yoda/event/PamelaRun.cpp
ViewVC logotype

Diff of /yoda/event/PamelaRun.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2.4 by kusanagi, Thu Dec 9 08:47:42 2004 UTC revision 2.5 by kusanagi, Thu Dec 16 17:32:46 2004 UTC
# Line 1  Line 1 
1  /** @file  /** @file
2   * $Author: kusanagi $   * $Author: kusanagi $
3   * $Date: 2004/12/03 22:04:04 $   * $Date: 2004/12/09 08:47:42 $
4   * $Revision: 2.3 $   * $Revision: 2.4 $
5   *   *
6   * Implementation of the PamelaRun class.   * Implementation of the PamelaRun class.
7   */   */
8  #include <iostream>  #include <iostream>
9  #include <iomanip>  #include <iomanip>
 #include <sstream>  
10  #include <list>  #include <list>
11  #include <exception>  #include <exception>
12  #include <string>  //#include <string>
13  #include <log4cxx/logger.h>  #include <log4cxx/logger.h>
14    
15  #include <TFile.h>  //Substituted by Maurizio 05 Feb 2004  #include <TFile.h>  //Substituted by Maurizio 05 Feb 2004
# Line 35  extern "C" { Line 34  extern "C" {
34  using namespace pamela;  using namespace pamela;
35    
36  static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.PamelaRun"));  static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.PamelaRun"));
 static std::stringstream oss;  
37    
38  /**  /**
39   * Get the run name according to a certain run number.   * Get the run name according to a certain run number.
# Line 43  static std::stringstream oss; Line 41  static std::stringstream oss;
41   * @return a string with the run name.   * @return a string with the run name.
42   */   */
43  std::string PamelaRun::GetRunName(int run) {  std::string PamelaRun::GetRunName(int run) {
44    std::ostringstream t_Stream;    std::stringstream temp;
45    t_Stream << std::setw( 4 ) << std::setfill( '0' ) << run;    temp.str("");
46    return "Run" + t_Stream.str();    temp << std::setw( 4 ) << std::setfill( '0' ) << run;
47      return "Run" + temp.str();
48  }  }
49    
50  /**  /**
# Line 75  return res; Line 74  return res;
74   * @param int run - Number of the run to check   * @param int run - Number of the run to check
75   * @return int   * @return int
76   */   */
77   std::string PamelaRun::RunExists(std::string input) throw (std::exception){   void PamelaRun::RunExists(std::string input) throw (std::exception){
78   int res;   int res;
79   DIR *dirp;   DIR *dirp;
80   std::string fileName;   std::string fileName;
81   std::string pathDir((char*)getenv("YODA_DATA"));   std::string pathDir((char*)getenv("YODA_DATA"));
82   std::string tempName;   std::string tempName;
83   std::string::size_type pos;   std::string::size_type pos;
84   std::ostringstream t_Stream;  
   
85   pos = input.find_last_of("/");   pos = input.find_last_of("/");
86   //if ((pos == std::string::npos) && !input.empty()) ;//throw Exception("Directories not allowed....");   //if ((pos == std::string::npos) && !input.empty()) ;//throw Exception("Directories not allowed....");
87   fileName = input.substr(pos+1);   fileName = input.substr(pos+1);
88   pos = fileName.find_last_of(".");   pos = fileName.find_last_of(".");
89   fileName = fileName.substr(0,pos);   fileName = fileName.substr(0,pos);
90   pathDir = pathDir + "/";   pathDir = pathDir + "/";
91   tempName = pathDir + fileName;   tempName = pathDir + fileName + "00";
92     //oss << pathDir << fileName << std::setw( 2 ) << std::setfill( '0' );
93     oss.str(tempName.c_str());
94   int i = 0;   int i = 0;
95   while (res){   while (res){
96      if ((dirp = opendir(tempName.c_str())) == NULL) {      //if ((dirp = opendir(tempName.c_str())) == NULL) {
97        if ((dirp = opendir(oss.str().c_str())) == NULL) {
98          res = 0;          res = 0;
99      } else {      } else {
100          closedir(dirp);          closedir(dirp);
101          t_Stream.str("");          oss.str("");
102          t_Stream << std::setw( 2 ) << std::setfill( '0' ) << ++i;          oss << pathDir << fileName << std::setw( 2 ) << std::setfill( '0' ) << ++i;
         tempName = pathDir + fileName + t_Stream.str() ;  
103          res = 1;          res = 1;
104      }      }
105   }   }
106  return (fileName + t_Stream.str());   oss.str("");
107     oss << Path << "/" << fileName << std::setw( 2 ) << std::setfill( '0' ) << i;
108     Path = oss.str();
109     oss.str("");
110     oss << fileName << std::setw( 2 ) << std::setfill( '0' ) << i;
111     Run = oss.str();
112    //return (oss.str());
113  }  }
114    
115  /**  /**
# Line 113  return (fileName + t_Stream.str()); Line 118  return (fileName + t_Stream.str());
118   * @param path Base path name to the data   * @param path Base path name to the data
119   */   */
120  PamelaRun::PamelaRun(std::string fileName, std::string path):  PamelaRun::PamelaRun(std::string fileName, std::string path):
121    Path(path),    Path(path),
122      Run(fileName),
123    RunNumber(1){ //veirificare se è possibilie eliminare questa variabile    RunNumber(1){ //veirificare se è possibilie eliminare questa variabile
124    logger->debug(_T("Constructor"));    logger->debug(_T("Constructor"));
125    Run = RunExists(fileName);    //Run = RunExists(fileName);
126      RunExists(fileName);
127    info = RunInfo(this);    info = RunInfo(this);
128  }  }
129    
# Line 127  PamelaRun::PamelaRun(std::string fileNam Line 134  PamelaRun::PamelaRun(std::string fileNam
134   * @return the complete path for this event type.   * @return the complete path for this event type.
135   */   */
136  std::string PamelaRun::GetDirName(PacketType const * type) const {  std::string PamelaRun::GetDirName(PacketType const * type) const {
137    std::string EventType = type->GetName();      //std::stringstream oss;
138    return Path + "/" + Run + "/" + EventType;      //std::string name = type->GetName();
139        //oss.str("");
140        //oss << Path << "/" << Run << "/" << "pippo";
141        //return oss.str();
142        //return "pippo";
143      //std::string EventType = type->GetName();
144        return Path + "/" + Run + "/" + type->GetName();
145  }  }
146    
147  /**  /**
# Line 137  std::string PamelaRun::GetDirName(Packet Line 150  std::string PamelaRun::GetDirName(Packet
150   * @param name subpacket name.   * @param name subpacket name.
151   * @return the complete path and file name.   * @return the complete path and file name.
152   */   */
153  std::string PamelaRun::GetFileName(const SubPacket* type, std::string name) const {  std::string PamelaRun::GetFileName(const SubPacket* type, std::string name) {
154    if (type->IsDetectorSpecific()) {    if (type->IsDetectorSpecific()) {
155      return GetDirName(type->GetPacketType()) + "/"      return Path + "/" + type->GetPacketType()->GetName() + "/"
156        + type->GetSubDetector()->GetName() + "/"        + Run + "." + type->GetPacketType()->GetName() + "."
       + Run + "." + type->GetPacketType()->GetName() + "."  
157        + type->GetSubDetector()->GetName() + "."        + type->GetSubDetector()->GetName() + "."
158        + name + ".root";        + name + ".root";
159    } else {    } else {
160      return GetDirName(type->GetPacketType()) + "/"      return Path + "/" + type->GetPacketType()->GetName() + "/"
161        + Run + "." + type->GetPacketType()->GetName() + "."        + Run + "." + type->GetPacketType()->GetName() + "."
162        + name + ".root";        + name + ".root";
163       /*
164        return Path + "/" + type->GetPacketType()->GetName() + "/"
165          + Run + "." + type->GetPacketType()->GetName() + "."
166          + name + ".root"; */
167    }    }
168  }  }
169    
# Line 156  std::string PamelaRun::GetFileName(const Line 172  std::string PamelaRun::GetFileName(const
172   * @param type subpacket type.   * @param type subpacket type.
173   * @return the complete path and file name.   * @return the complete path and file name.
174   */   */
175  std::string PamelaRun::GetFileName(const SubPacket* type) const {  std::string PamelaRun::GetFileName(const SubPacket* type)  {
176    return GetFileName(type, type->GetSubPacketName());    //return GetFileName(type, type->GetSubPacketName());
177        return GetFileName(type, "pippo");
178  }  }
179    
180  /**  /**
# Line 194  static std::list<std::string> GetRootFil Line 211  static std::list<std::string> GetRootFil
211    std::list<std::string> files;    std::list<std::string> files;
212    DIR *dir = opendir(path.c_str());    DIR *dir = opendir(path.c_str());
213    if (dir == 0) {    if (dir == 0) {
214      oss.str("");      logger->debug("Could not open " + path);
     oss <<  "Could not open " << path;  
     logger->debug(oss.str().c_str());  
215      //throw Exception("Could not open " + path);      //throw Exception("Could not open " + path);
216    }    }
217        
# Line 217  static std::list<std::string> GetRootFil Line 232  static std::list<std::string> GetRootFil
232        if (stat(nextfilename.c_str(), &buf) == 0) {        if (stat(nextfilename.c_str(), &buf) == 0) {
233          filename.insert(filename.size()-5, "*");          filename.insert(filename.size()-5, "*");
234        }        }
235        oss.str("");        logger->debug("Using " + filename);
       oss <<  "Using " << filename;  
       logger->debug(oss.str().c_str());  
236        files.push_back(filename);        files.push_back(filename);
237      }      }
238    }    }
# Line 257  static void AddAllAsFriend(TChain* tree, Line 270  static void AddAllAsFriend(TChain* tree,
270    }    }
271    TFile* File = new TFile(BaseFileName.c_str(), "read");    TFile* File = new TFile(BaseFileName.c_str(), "read");
272    if (!File->IsOpen()) {    if (!File->IsOpen()) {
273      oss.str("");      logger->warn("Could not open file " + BaseFileName + " for reading.");
     oss <<  "Could not open file " << BaseFileName << " for reading.";  
     logger->warn(oss.str().c_str());  
274      return;      return;
275    }    }
276    TList* list = File->GetListOfKeys();    TList* list = File->GetListOfKeys();
# Line 270  static void AddAllAsFriend(TChain* tree, Line 281  static void AddAllAsFriend(TChain* tree,
281          TChain* FriendChain = new TChain(TreeName.c_str());          TChain* FriendChain = new TChain(TreeName.c_str());
282          FriendChain->Add(FileName.c_str());          FriendChain->Add(FileName.c_str());
283          tree->AddFriend(FriendChain, TreeName.c_str());          tree->AddFriend(FriendChain, TreeName.c_str());
284          oss.str("");          //logger->warn("Adding chain " + TreeName + " with " + FriendChain->GetEntries() + " entries as Friend");
         oss << "Adding chain " << TreeName << " with "  
             << FriendChain->GetEntries() << " entries as Friend";  
         logger->warn(oss.str().c_str());  
285        }        }
286      }      }
287      File->Close();      File->Close();
# Line 283  static void AddAllAsFriend(TChain* tree, Line 291  static void AddAllAsFriend(TChain* tree,
291          std::string TreeName = k->GetName();          std::string TreeName = k->GetName();
292          TTree* FriendTree = (TTree *)File->Get(TreeName.c_str());          TTree* FriendTree = (TTree *)File->Get(TreeName.c_str());
293          tree->AddFriend(FriendTree, TreeName.c_str());            tree->AddFriend(FriendTree, TreeName.c_str());  
294          oss.str("");          //logger->debug("Adding tree " + TreeName + " with " + FriendTree->GetEntries() + " entries as Friend");
         oss << "Adding tree " << TreeName << " with "  
             << FriendTree->GetEntries() << " entries as Friend";  
         logger->debug(oss.str().c_str());  
295        }        }
296      }      }
297    }    }
# Line 405  TTree* PamelaRun::CreateTTree(Algorithm* Line 410  TTree* PamelaRun::CreateTTree(Algorithm*
410    TFile* File = new TFile(FileName.c_str(), "create");    TFile* File = new TFile(FileName.c_str(), "create");
411    File->SetCompressionLevel(5);    File->SetCompressionLevel(5);
412    if (!File->IsOpen()) {    if (!File->IsOpen()) {
413      oss.str("");      logger->error("Could not open file " + FileName);
     oss <<  "Could not open file " << FileName ;  
     logger->error(oss.str().c_str());  
414      //throw Exception("Could not open file " + FileName);      //throw Exception("Could not open file " + FileName);
415    }    }
416    std::string TreeName = GetTreeName(packet);    std::string TreeName = GetTreeName(packet);
# Line 417  TTree* PamelaRun::CreateTTree(Algorithm* Line 420  TTree* PamelaRun::CreateTTree(Algorithm*
420    AlgorithmInfo ai(algo);    AlgorithmInfo ai(algo);
421    ai.Write();    ai.Write();
422    info.Write();    info.Write();
423    oss.str("");    logger->info("Creating file " + FileName + " with Tree " + TreeName);
   oss <<  "Creating file " << FileName << " with Tree " << TreeName;  
   logger->info(oss.str().c_str());  
424    return tree;    return tree;
425  }  }
426    
# Line 482  void PamelaRun::WriteHeader(Algorithm* a Line 483  void PamelaRun::WriteHeader(Algorithm* a
483    CreateDirectoryStructure(FileName.c_str());    CreateDirectoryStructure(FileName.c_str());
484    TFile* File = new TFile(FileName.c_str(), "create");    TFile* File = new TFile(FileName.c_str(), "create");
485    if (!File->IsOpen()) {    if (!File->IsOpen()) {
486      oss.str("");      logger->error("Could not open file " + FileName);
     oss     <<  "Could not open file " << FileName ;  
     logger->error(oss.str().c_str());  
487      //throw Exception("Could not open file " + FileName);      //throw Exception("Could not open file " + FileName);
488    }    }
489    //std::string TreeName = GetTreeName(packet);    //std::string TreeName = GetTreeName(packet);
# Line 494  void PamelaRun::WriteHeader(Algorithm* a Line 493  void PamelaRun::WriteHeader(Algorithm* a
493    AlgorithmInfo ai(algo);    AlgorithmInfo ai(algo);
494    ai.Write();    ai.Write();
495    info.Write();    info.Write();
496    oss.str("");    std::stringstream temp;
497    oss <<  "Created file " << FileName << " with Tree Pscu";    //temp.str("");
498    logger->info(oss.str().c_str());    //temp << "Created file" << FileName.c_str() << " with Tree Pscu" ;
499      //logger->info(temp.str());
500    tree->Branch(GetDefaultBranchName(&header).c_str(),    tree->Branch(GetDefaultBranchName(&header).c_str(),
501                 (*subpacket)->Class()->GetName(), subpacket);                 (*subpacket)->Class()->GetName(), subpacket);
502    TTreeMap.insert(RootTreeMap::value_type(type, tree));    TTreeMap.insert(RootTreeMap::value_type(type, tree));
# Line 522  void PamelaRun::WriteHeaders(Algorithm* Line 522  void PamelaRun::WriteHeaders(Algorithm*
522      WriteHeader(algo, subpacket, PacketType::CalibTof);      WriteHeader(algo, subpacket, PacketType::CalibTof);
523      WriteHeader(algo, subpacket, PacketType::CalibS4);      WriteHeader(algo, subpacket, PacketType::CalibS4);
524      WriteHeader(algo, subpacket, PacketType::CalibCalPed);      WriteHeader(algo, subpacket, PacketType::CalibCalPed);
525      WriteHeader(algo, subpacket, PacketType::CalibAc);      WriteHeader(algo, subpacket, PacketType::Calib1_Ac1);
526        WriteHeader(algo, subpacket, PacketType::Calib1_Ac2);
527        WriteHeader(algo, subpacket, PacketType::Calib2_Ac1);
528        WriteHeader(algo, subpacket, PacketType::Calib2_Ac2);
529      WriteHeader(algo, subpacket, PacketType::RunHeader);      WriteHeader(algo, subpacket, PacketType::RunHeader);
530      WriteHeader(algo, subpacket, PacketType::RunTrailer);      WriteHeader(algo, subpacket, PacketType::RunTrailer);
531      WriteHeader(algo, subpacket, PacketType::CalibHeader);      WriteHeader(algo, subpacket, PacketType::CalibHeader);
# Line 539  void PamelaRun::WriteHeaders(Algorithm* Line 542  void PamelaRun::WriteHeaders(Algorithm*
542      WriteHeader(algo, subpacket, PacketType::Tmtc);      WriteHeader(algo, subpacket, PacketType::Tmtc);
543      WriteHeader(algo, subpacket, PacketType::Mcmd);      WriteHeader(algo, subpacket, PacketType::Mcmd);
544      WriteHeader(algo, subpacket, PacketType::ForcedFECmd);      WriteHeader(algo, subpacket, PacketType::ForcedFECmd);
545      WriteHeader(algo, subpacket, PacketType::AcInit);      WriteHeader(algo, subpacket, PacketType::Ac1Init);
546      WriteHeader(algo, subpacket, PacketType::CalInit);      WriteHeader(algo, subpacket, PacketType::CalInit);
547      WriteHeader(algo, subpacket, PacketType::TrkInit);      WriteHeader(algo, subpacket, PacketType::TrkInit);
548      WriteHeader(algo, subpacket, PacketType::TofInit);      WriteHeader(algo, subpacket, PacketType::TofInit);
549      WriteHeader(algo, subpacket, PacketType::TrgInit);          WriteHeader(algo, subpacket, PacketType::TrgInit);    
550      WriteHeader(algo, subpacket, PacketType::NdInit);          WriteHeader(algo, subpacket, PacketType::NdInit);    
551      WriteHeader(algo, subpacket, PacketType::S4Init);          WriteHeader(algo, subpacket, PacketType::S4Init);    
552        WriteHeader(algo, subpacket, PacketType::Ac2Init);
553      WriteHeader(algo, subpacket, PacketType::CalAlarm);          WriteHeader(algo, subpacket, PacketType::CalAlarm);    
554      WriteHeader(algo, subpacket, PacketType::AcAlarm);          WriteHeader(algo, subpacket, PacketType::AcAlarm);    
555      WriteHeader(algo, subpacket, PacketType::TrkAlarm);          WriteHeader(algo, subpacket, PacketType::TrkAlarm);    
# Line 588  void PamelaRun::FillTrees(const PacketTy Line 592  void PamelaRun::FillTrees(const PacketTy
592  }  }
593    
594    
595    

Legend:
Removed from v.2.4  
changed lines
  Added in v.2.5

  ViewVC Help
Powered by ViewVC 1.1.23